import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter);

// //获取原型对象上的push函数
// const originalPush = Router.prototype.push;
// //修改原型对象中的push方法
// Router.prototype.push = function push(location) {
//     return originalPush.call(this, location).catch((err) => err);
// };

const routes = [
  {
    path: "/",
    redirect: '/logIn'
  },
  // 登录
  {
    path: "/logIn",
    name: "logIn",
    component: () => import("@/pages/login.vue"),
  },
  // 注册
  {
    path: "/register",
    name: "register",
    component: () => import("@/pages/register.vue"),
  },
  // 找回密码
  {
    path: "/retrievePassword",
    name: "retrievePassword",
    component: () => import("@/pages/retrievePassword.vue"),
  },
];
//解决路由多次点击报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const router = new VueRouter({
  routes,
  mode: "hash",
});

/**
 * 路由拦截
 */
// router.beforeEach(function interceptor(to,from, next) {
//   if (to.meta.nologin) {
//     next();
//     return;
//   }
//   let token = store.getters["common/token"];
//   if (!!token) {
//     next();
//   } else {
//     router.push("/Shouye");
//     // console.log("前端没有token");
//     throw new Error ("前端没有token")
//   }
// });
export default router;